using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PipelineTemplateEditor.Util;

namespace PipelineTemplateEditor
{
    public partial class OpenDialog : Form
    {
        List<ComboBoxItem> templateTypes = new List<ComboBoxItem>();
        public int TemplateID = -1;

        public OpenDialog()
        {
            InitializeComponent();
        }

        private void OpenDialog_Load(object sender, EventArgs e)
        {
            templateTypes = Util.ConnectionManager.GetTemplateList();
            cbTemplates.DataSource = templateTypes;
        }

        private void OpenDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                if (cbTemplates.SelectedIndex > -1)
                {
                    TemplateID = int.Parse(((ComboBoxItem)cbTemplates.SelectedItem).Value);
                }
                else
                {
                    TemplateID = -1;
                    if (MessageBox.Show("You have not selected anything. Are you sure you wish to close the form?", "Closing", MessageBoxButtons.YesNo) == DialogResult.No)
                        e.Cancel = true;
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}